package com.dsa.team5.kanban.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.dsa.team5.kanban.dao.TaskDao;
import com.dsa.team5.kanban.model.Task;
import com.dsa.team5.kanban.utils.CustomHibernateDaoSupport;

@Repository("taskDao")
public class TaskDaoImpl extends CustomHibernateDaoSupport implements TaskDao {

	@Autowired
	SessionFactory sessionFactory;

	@Override
	public void save(Task task) {
		getHibernateTemplate().save(task);

	}

	@Override
	public void update(Task task) {
		getHibernateTemplate().update(task);

	}

	@Override
	public void delete(Task task) {
		getHibernateTemplate().delete(task);
	}
	
	@Override
	public Task getTaskByTaskId(Long taskId) {
		return (Task) getHibernateTemplate().find(
				"from Task where taskId = " + taskId).get(0);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Task> getTaskByStatusId(Long statusId) {
		return getHibernateTemplate().find(
				"from Task where statusId = " + statusId
						+ " order by taskId asc");
	}
}
